
#include "StateAchievements.h"
#include "StateManager.h"
#include "StateMainMenu.h"

#include "defs.h"
#include "InputManager.h"
#include "AudioUtils.h"

StateAchievements::StateAchievements()
{
}

StateAchievements::~StateAchievements()
{
}

void StateAchievements::loadContent()
{
    m_bg = new RenderableEntity("BG_Background", Vector2());
    
	m_tTitle = new TextEntity("Achievements", FONT_NAME, 100, Vector2(320, 850), 1, 2);
	m_tTitle->setCenter(Vector2(0.5, 0.5));
	
    m_tBack = new TextEntity("Back", FONT_NAME, 64, Vector2(80, 80));
    m_tBack->changeColorWhenClicked(true, COLOR_BLACK);

	m_eEnter = new TimeLineEffect(false, false);
	
	m_eExit = new TimeLineEffect(false, false);
}

void StateAchievements::unloadContent()
{
    delete m_bg;

    delete m_tTitle;
    delete m_tBack;

	delete m_eEnter;
	delete m_eExit;
}

void StateAchievements::enter()
{
	m_eState = Enter;
	m_eEnter->start(true);
}

void StateAchievements::update(float dt)
{
	switch(m_eState)
	{
		case Enter:
			if(m_eEnter->isFinished())
			{
				m_eState = Idle;
			}
			break;

		case Idle:
			m_tBack->update();
			
			if(m_tBack->isClicked())
			{
				m_eExit->start(true);
				m_eState = Exit;
			}
			break;
			
		case Exit:
			if(m_eExit->isFinished())
			{
				StateManager::instance().setState(StateMainMenu::instance());
			}
			break;
	}
}

void StateAchievements::render()
{
    m_bg->render();
	
	m_tTitle->renderShadow();
	m_tTitle->render();

    m_tBack->renderShadow();	
    m_tBack->render();    	
}

void StateAchievements::exit()
{
}
